package avicit.bdp.dms.tdm.service;

import avicit.bdp.dms.tdm.dao.AssetCatalogAuthSettingDAO;
import avicit.bdp.dms.tdm.dto.AssetCatalogAuthSettingDTO;
import avicit.platform6.commons.utils.ComUtil;
import avicit.platform6.commons.utils.PojoUtil;
import avicit.platform6.core.context.ThreadContextHelper;
import avicit.platform6.core.exception.BusinessException;
import avicit.platform6.core.properties.PlatformConstant;
import avicit.platform6.core.rest.msg.QueryReqBean;
import avicit.platform6.modules.system.syslog.service.SysLogUtil;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class AssetCatalogAuthSettingService {

  private static final Logger logger =
      LoggerFactory.getLogger(AssetCatalogAuthSettingService.class);

  @Autowired private AssetCatalogAuthSettingDAO assetCatalogAuthSettingDAO;

  /** 全部删除 */
  public void delete() {
    assetCatalogAuthSettingDAO.deleteAll();
  }

  /**
   * 新增对象
   *
   * @param dto 保存对象
   * @return String
   */
  @Transactional
  public String insert(AssetCatalogAuthSettingDTO dto) {
    try {
      dto.setId(ComUtil.getId());
      dto.setStatus("0");
      PojoUtil.setSysProperties(dto, PlatformConstant.OpType.insert);
      assetCatalogAuthSettingDAO.insert(dto);
      // 记录日志
      SysLogUtil.log4Insert(dto);
      return dto.getId();
    } catch (Exception e) {
      logger.error(e.getMessage(), e);
      throw new BusinessException("新增对象失败");
    }
  }

  /**
   * 按条件查询
   *
   * @param queryReqBean 查询条件
   */
  @Transactional(readOnly = true)
  public List<AssetCatalogAuthSettingDTO> searchList(
      QueryReqBean<AssetCatalogAuthSettingDTO> queryReqBean) {
    try {
      return assetCatalogAuthSettingDAO.searchList(
          queryReqBean.getSearchParams(),
          ThreadContextHelper.getOrgId(),
          ThreadContextHelper.getWordSecret());
    } catch (Exception e) {
      logger.error(e.getMessage(), e);
      throw new BusinessException("查询失败");
    }
  }
}
